import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3, reqAttr } from '@/api/product/attr'
import { CategoryState } from './types/type'
export const useCategoryStore = defineStore('category', {
  state: (): CategoryState => {
    return {
      c1Id: '',
      c1Arr: [],
      c2Arr: [],
      c2Id: '',
      c3Arr: [],
      c3Id: '',
    }
  },
  actions: {
    async getC1() {
      let result = await reqC1()
      if (result.code == 200) {
        this.c1Arr = result.data
      }
    },
    async getC2() {
      let result = await reqC2(this.c1Id)
      if (result.code == 200) {
        this.c2Arr = result.data
      }
    },
    async getC3() {
      let result = await reqC3(this.c2Id)
      if (result.code == 200) {
        this.c3Arr = result.data
      }
    },
    async getAttr() {
      let result = await reqAttr(this.c1Id, this.c2Id, this.c3Id)
      console.log(result)
    },
  },
  getters: {
    //
  },
})
